package com.icinfo.cloud.provider.punish.config.enums;

import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 自由裁量规则（违法情形配置）配置类型
 *
 * @author Junfeng.Chen
 * @date 2024/1/31 8:52
 **/
@Getter
@AllArgsConstructor
public enum DiscretionRuleTypeEnum {
    /**
     * 区间金额
     */
    RANGE("1", "区间金额"),
    /**
     * 固定金额
     */
    FIX("2", "固定金额"),
    ;

    /**
     * 编码
     */
    private final String code;
    /**
     * 描述
     */
    private final String desc;

    /**
     * 根据code获取枚举
     *
     * @param code
     * @return
     */
    public static DiscretionRuleTypeEnum getByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        for (DiscretionRuleTypeEnum e : DiscretionRuleTypeEnum.values()) {
            if (e.getCode().equals(code)) {
                return e;
            }
        }
        throw new BusinessException("转换枚举异常");
    }
}
